<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>WinGetText</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
</head>
<body>

<h1>WinGetText</h1>

<p>Retrieves the text from the specified window.</p>

<pre class="Syntax">WinGetText, OutputVar [, WinTitle, WinText, ExcludeTitle, ExcludeText]</pre>
<h3>Parameters</h3>
<dl>

  <dt>OutputVar</dt>
  <dd><p>The name of the variable in which to store the retrieved text.</p></dd>

  <dt>WinTitle</dt>
  <dd><p>A window title or other criteria identifying the target window. See <a href="../misc/WinTitle.htm">WinTitle</a>.</p></dd>

  <dt>WinText</dt>
  <dd><p>If present, this parameter must be a substring from a single text element of the target window (as revealed by the included Window Spy utility). Hidden text elements are detected if <a href="DetectHiddenText.htm">DetectHiddenText</a> is ON.</p></dd>

  <dt>ExcludeTitle</dt>
  <dd><p>Windows whose titles include this value will not be considered.</p></dd>

  <dt>ExcludeText</dt>
  <dd><p>Windows whose text include this value will not be considered.</p></dd>

</dl>

<h3>ErrorLevel</h3>
<p><span class="ver">[v1.1.04+]</span> This command is able to throw an exception on failure. For more information, see <a href="Catch.htm#RuntimeErrors">Runtime Errors</a>.</p>
<p><a href="../misc/ErrorLevel.htm">ErrorLevel</a> is set to 1 if there was a problem or 0 otherwise.</p>
<h3>Remarks</h3>
<p>The text retrieved is generally the same as what Window Spy shows for that window. However, if <a href="DetectHiddenText.htm">DetectHiddenText</a> has been turned off, hidden text is omitted from <em>OutputVar</em>.</p>
<p>Each text element ends with a carriage return and linefeed (CR+LF), which can be represented in the script as `r`n. To extract individual lines or substrings, use commands such as <a href="StringGetPos.htm">StringGetPos</a> and <a href="StringMid.htm">StringMid</a>. A  <a href="LoopParse.htm">parsing loop</a> can also be used to examine each line or word one by one.</p>
<p>If the retrieved text appears to be truncated (incomplete), try using <code><a href="VarSetCapacity.htm">VarSetCapacity(OutputVar, 55)</a></code> prior to WinGetText [replace 55 with a size that is considerably longer than the truncated text]. This is necessary because some applications do not respond properly to the WM_GETTEXTLENGTH message, which causes AutoHotkey to make the output variable too small to fit all the text.</p>
<p>The amount of text retrieved is limited to a variable's maximum capacity (which can be changed via the <a href="_MaxMem.htm">#MaxMem</a> directive). As a result, this command might use a large amount of RAM if the target window (e.g. an editor with a large document open) contains a large quantity of text. To avoid this, it might be possible to retrieve only portions of the window's text by using <a href="ControlGetText.htm">ControlGetText</a> instead. In any case, a variable's memory can be freed later by assigning it to nothing, i.e. <code>OutputVar =</code>.</p>
<p>To retrieve a list of all controls in a window, follow this example: <code><a href="WinGet.htm">WinGet</a>, OutputVar, ControlList, WinTitle</code></p>
<p>Window titles and text are case sensitive. Hidden windows are not detected unless <a href="DetectHiddenWindows.htm">DetectHiddenWindows</a> has been turned on.</p>

<h3>Related</h3>
<p><a href="ControlGetText.htm">ControlGetText</a>, <a href="WinGetActiveStats.htm">WinGetActiveStats</a>, <a href="WinGetActiveTitle.htm">WinGetActiveTitle</a>, <a href="WinGetTitle.htm">WinGetTitle</a>, <a href="WinGetPos.htm">WinGetPos</a>, <a href="_MaxMem.htm">#MaxMem</a></p>
<h3>Example</h3>
<pre class="NoIndent">Run, Calc.exe
WinWait, Calculator
WinGetText, text  <em>; The window found above will be used.</em>
MsgBox, The text is:`n%text%</pre>

</body>
</html>
